<template>
    <div class="login" style="overflow: auto;">
          <!--密码登录-->
           <div class="header" @click="$router.push({name:'autoLogin',query:{hid:hid}})">动态码登录</div>
             <div class="lhs">龙虎山</div>
<div class="tel">
    <input type="text" placeholder="手机号" v-model="uphone">
</div>
        <div class="pwd">
        <input type="password" placeholder="密码" v-model="upwd"  ref="inp1"><i @click="disp('i_f','inp1')" ref="i_f" class="iconfont icon-biyan"></i>
        </div>
        <div class="btnLogin" @click="dologin">登录</div>
        <div class="xieyi"></div>

    </div>
</template>

<script>
import { Toast } from 'mint-ui';

export default {
  name: 'pwdLogin',
  data() {
    return {
      uphone: '',
      upwd: '',
      hid: '',
    };
  },
  mounted() {
    this.hid = this.$route.query.hid;
    console.log(this.hid);
  },
  methods: {
    async dologin() {
      const res = await this.$api.post('/user/login', {
        telphone: this.uphone,
        password: this.upwd,
        type: 1,
      });

      console.log(res);

      if (res.data.state) {
        Toast({
          message: '正在登陆,请稍等...',
          iconClass: 'icon icon-success',
        });

        this.$store.commit('updateUserinfo', res.data.data.userinfo);
        setTimeout(() => {
          if (this.$route.query.hid) {
            this.$router.replace({ name: 'detail', query: { hid: this.$route.query.hid } });
          } else {
            this.$router.replace({ name: 'usercenter' });
          }
        }, 2000);
      } else {
        Toast({
          message: `失败${res.data.info}`,
          iconClass: 'icon icon-cuowushibaibukeyong',
        });
      }
    },

    disp(_ref, inp) {
      this.$refs[_ref].className = this.$refs[_ref].className === 'iconfont icon-biyan' ? 'iconfont icon-eyesopen' : 'iconfont icon-biyan';
      this.$refs[inp].type = this.$refs[_ref].className === 'iconfont icon-biyan' ? 'password' : 'text';
    },

  },
};
</script>

<style scoped>

</style>
